﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Single_Index.aspx.cs" Inherits="ncp.Web.cms.work.SingleManager.Single_Index" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="../../themes/icon.css" />
    <link href="../../css/base.css" rel="stylesheet" type="text/css" />
    <link href="/Plugin/ueditor/themes/default/ueditor.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="../../js/jquery-1.7.1.min.js"></script>
	<script type="text/javascript" src="../../js/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../../../js/common.js"></script>
<script src="/Plugin/ueditor/editor_all.js" type="text/javascript"></script>
    
    <script src="/Plugin/ueditor/editor_config.js" type="text/javascript"></script>
</head>
<body style="margin:0; padding:0px;">
<form id="form1" runat="server">
    <div>
        <div class="toolbar" style="background-color:#efefef">
	        <a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-edit" onclick="onEditNews();">编辑</a>
        </div>
        <div id="divright">    
        </div>
	    <div id="divNewsInfoBox">
	        <div class="form mod-content">
            <table>
                <tr>
                    <td>
                    <script type="text/plain" id="newsContent">
                    </script>
                    </td>
                </tr>
                <tr>
            <td style="text-align: center;border-bottom: none;">
                <a href="javascript:void(0)" class="easyui-linkbutton" onclick="onSaveNews()">确定</a>&nbsp;&nbsp;
	            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="onCloseNewsWindow()">关闭</a>
            </td>
        </tr>
            </table>
        </div>
	    </div>
	</div>
	</form>
</body>
</html>
<script type="text/javascript">
    $(function() { //初始化
    $("#rightlayout").css("height", $(window).height() + "px");
    $("#west,#east").css("height", ($(window).height() - 35) + "px");
        initDialog();
    });
    //加载编辑器
    var editor = new baidu.editor.ui.Editor({
        toolbars: nomalToolbar,
        minFrameHeight: $(window).height()-155,
        elementPathEnabled: false
    });
    editor.render("newsContent");
    //关闭新闻发布窗口
    function onCloseNewsWindow() {
        emptyData();
        $('#divNewsInfoBox').window('close');
    }
    //清空数据
    function emptyData() {
        $("#linkName,#description").val("");
        $("#sort").val(1);
        $("#webAddr").val("http://");
    }
    
    //初始化对话框
    function initDialog() {
        $('#divNewsInfoBox').dialog({
            title: '编辑内容',
            modal: true,
            width: $(window).width(),
            height: $(window).height(),
            left: 0,
            top: 0,
            padding: 10,
            closed: true,
            draggable: false,
                closable:false
        });
    }

</script>

<%--商品信息--%>
<script type="text/javascript">
    var pageobj = new Object();

    $(function() {
        initPageObj();
        initDatagrid();
        onSearch();
    });

   
    //初始化页码对象
    function initPageObj() {
        pageobj.currentpageindex = 1;
        pageobj.pagesize = 15;
        pageobj.sorting = "SingleClass_Id";
        pageobj.sortdir = "asc";
        pageobj.recordcount = GetRecordCount();
    }

    //初始化表格
    function initDatagrid() {
        $('#divright').datagrid({
        height: $(window).height() - 61,
            nowrap: true,
            striped: true,
            singleSelect: true,
            sortName: 'SingleClass_Id',
            sortOrder: 'asc',
            remoteSort: false,
            idField: 'SingleClass_Id',
            pagination: true,
            rownumbers: true,
            columns: [[
					{ field: 'SingleClass_Id', title: '编号', hidden: 'true', width: 80 },
					{ field: 'SingleClass_Name', title: '名称', sortable: 'true', width: 150 },
					{ field: 'SingleClass_Template', title: '模板地址', sortable: 'false', width: 200 },
					{ field: 'SingleClass_Path', title: '预览', sortable: 'false', width: 50,
					    formatter: function(val, rec) {
					        return "<a href=\""+val+"\" target=\"_blank\">预览</a>";
					    }
					}
				]]
        });
    }


    function initPager() {
        var p = $('#divright').datagrid('getPager');
        $(p).pagination({
            total: pageobj.recordcount,
            pageSize: pageobj.pagesize,
            pageList: [15, 20, 25, 30],
            showRefresh: true,
            showPageList:true,
            beforePageText: '第',
            afterPageText: '页 共 {pages} 页',
            displayMsg: '当前显示 {from} - {to} 条记录 共 {total} 条记录',
            onSelectPage: function(pageNumber, pageSize) {
                $(this).pagination('loading');
                onShowPageNo(pageNumber, pageSize);
                $(this).pagination('loaded');
            }
        });
    }
    
    //翻页
    function onShowPageNo(pageNumber, pageSize) {
        pageobj.pagesize = pageSize;
        pageobj.currentpageindex = pageNumber;
        LoadNewsInfo();
        initPager();
        return false;
    }

    //得到总记录数
    function GetRecordCount() {
        var response = ncp.Web.cms.work.SingleManager.Single_Index.GetRecordCount();
        if (response.value != null) {    
            return response.value;
        }
        else
            return 0;
    }

    //查询
    function onSearch() {
        pageobj.currentpageindex = 1;
        pageobj.recordcount = GetRecordCount();
        LoadNewsInfo();
        initPager();
        return false;
    }

    //装载商品信息视图
    function LoadNewsInfo() {
        var jsonStr = $.objectToJson(pageobj);

        var response = ncp.Web.cms.work.SingleManager.Single_Index.BindTable(jsonStr);
        if (response.value != null) {
            var data = eval(response.value);
            $('#divright').datagrid('loadData', data);
        }
        $('#divright').datagrid('clearSelections');
    }

    
    //保存新闻
    function onSaveNews() {
        var selected = $('#divright').datagrid('getSelected');
        if (selected) {
            var obj = new Object();
            obj.Single_Content = editor.getContent();
            obj.className = selected.SingleClass_Name;
            obj.Single_Class = selected.SingleClass_Id;
            obj.path = selected.SingleClass_Path;
            obj.temPath = selected.SingleClass_Template;
            var response = ncp.Web.cms.work.SingleManager.Single_Index.OnSave($.objectToJson(obj));
            if (response.value != "") {
                var jsonOBJ = eval(response.value)[0];
                alert(jsonOBJ.msg);
                if (jsonOBJ.isreload) {
                    onSearch();
                    onCloseNewsWindow();
                    emptyData();
                }
            }
        }
        else
            alert("请先选择一条记录！");
    }



    //编辑商品
    function onEditNews() {
        var selected = $('#divright').datagrid('getSelected');
        if (selected) {
            $('#divNewsInfoBox').dialog('setTitle', '编辑内容');
            $('#divNewsInfoBox').dialog("open");
            var content = selected.Single_Content == null ? "" : selected.Single_Content;
            editor.setContent(content);
        }
        else
            alert("请先选择一条记录！");
        return false;
    }
</script>